NEW_USER_STAY_ANALYSIS_CONFIG = {
    'real_time_report': False,
    'interval_type_list': ['day'],
    'dynamic_argument': True,
    'day_to_calc': range(0, 60),
    'target_event_id': ['active', 'register', 'recharge', 'bind_phone', 'cp_lottery', 'cp_game'],
    'values': [
        {
            "value_id": "new_device",
            "target_value": "_aid.keyword",
            "value_name": "新增设备",
            "filter": [
                {'term': {'_event_id': 'active'}},
                {'term': {"_is_new_device": 1}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "register_user",
            "target_value": "_user_id",
            "value_name": "注册账号",
            "filter": [
                {'term': {'_event_id': 'register'}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "register_rate",
            "value_name": "账号注册率",
            "value_expr": "register_user / new_device",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "seven_day_register_user",
            "target_value": "_user_id",
            "value_name": "7日注册账号",
            "filter": [
                {"term": {"_event_id": "register"}},
                {"terms": {"_aid.keyword": '${base_aid_list}'}}
            ],
            "time_range": {
                "_event_time": [0, 6]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "seven_day_register_rate",
            "value_name": "7日注册率",
            "value_expr": "seven_day_register_user / new_device",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "bind_user",
            "target_value": "_user_id",
            "value_name": "首日绑定账号",
            "filter": [
                {"term": {"_event_id": "bind_phone"}},
                {"term": {"_is_new_user": 1}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "bind_rate",
            "value_name": "首日绑定率",
            "value_expr": "bind_user / register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "seven_day_bind_user",
            "target_value": "_user_id",
            "value_name": "7日绑定账号",
            "filter": [
                {"term": {"_event_id": "bind_phone"}},
            ],
            "time_range": {
                "_registered_at": [0, 0],
                "_event_time": [0, 6]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "seven_day_bind_rate",
            "value_name": "7日绑定率",
            "value_expr": "seven_day_bind_user / seven_day_register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "recharge_user",
            "target_value": "_user_id",
            "value_name": "首日付费账号",
            "filter": [
                {"term": {"_event_id": "recharge"}},
                {"term": {"_is_new_user": 1}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "recharge_rate",
            "value_name": "首日付费率",
            "value_expr": "recharge_user / register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "seven_day_recharge_user",
            "target_value": "_user_id",
            "value_name": "7天付费账号",
            "filter": [
                {"term": {"_event_id": "recharge"}}
            ],
            "time_range": {
                "_registered_at": [0, 0],
                "_event_time": [0, 6]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "seven_day_recharge_rate",
            "value_name": "7日付费率",
            "value_expr": "seven_day_recharge_user / seven_day_register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "bet_user",
            "target_value": "_user_id",
            "value_name": "首日投注账号",
            "filter": [
                {"terms": {"_event_id": ["cp_lottery", "cp_game"]}},
                {"term": {"_is_new_user": 1}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "bet_rate",
            "value_name": "首日投注率",
            "value_expr": "bet_user / register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "seven_day_bet_user",
            "target_value": "_user_id",
            "value_name": "7日投注账号",
            "filter": [
                {"terms": {"_event_id": ["cp_lottery", "cp_game"]}}
            ],
            "time_range": {
                "_registered_at": [0, 0],
                "_event_time": [0, 6]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "seven_day_bet_rate",
            "value_name": "7日投注率",
            "value_expr": "seven_day_bet_user / seven_day_register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "stay_2_device",
            "target_value": "_aid.keyword",
            "value_name": "次日设备留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_device_active_days": 1}}
            ],
            "time_range": {
                "_event_time": [1, 1]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_3_device",
            "target_value": "_aid.keyword",
            "value_name": "3日设备留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_device_active_days": 2}}
            ],
            "time_range": {
                "_event_time": [2, 2]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_4_device",
            "target_value": "_aid.keyword",
            "value_name": "4日设备留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_device_active_days": 3}}
            ],
            "time_range": {
                "_event_time": [3, 3]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_5_device",
            "target_value": "_aid.keyword",
            "value_name": "5日设备留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_device_active_days": 4}}
            ],
            "time_range": {
                "_event_time": [4, 4]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_6_device",
            "target_value": "_aid.keyword",
            "value_name": "6日设备留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_device_active_days": 5}}
            ],
            "time_range": {
                "_event_time": [5, 5]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_7_device",
            "target_value": "_aid.keyword",
            "value_name": "7日设备留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_device_active_days": 6}}
            ],
            "time_range": {
                "_event_time": [6, 6]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_15_device",
            "target_value": "_aid.keyword",
            "value_name": "15日设备留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_device_active_days": 14}}
            ],
            "time_range": {
                "_event_time": [14, 14]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "stay_30_device",
            "target_value": "_aid.keyword",
            "value_name": "30日设备留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_device_active_days": 29}}
            ],
            "time_range": {
                "_event_time": [29, 29]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "seven_day_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "7日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 6],
                "_registered_at": [0, 0]
            },
            "hide_result": True,
            "adjust_amount": True
        },
        {
            "value_id": "seven_days_ltv",
            "value_name": "7日LTV",
            "value_expr": "seven_day_agg_recharge / register_user",
            "adjust_amount": True
        },
        {
            "value_id": "fourteen_day_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "14日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 13],
                "_registered_at": [0, 0]
            },
            "hide_result": True,
            "adjust_amount": True
        },
        {
            "value_id": "fourteen_days_ltv",
            "value_name": "14日LTV",
            "value_expr": "fourteen_day_agg_recharge / register_user",
            "adjust_amount": True
        },
        {
            "value_id": "month_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "30日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 29],
                "_registered_at": [0, 0]
            },
            "hide_result": True,
            "adjust_amount": True
        },
        {
            "value_id": "month_ltv",
            "value_name": "30日LTV",
            "value_expr": "month_agg_recharge / register_user",
            "adjust_amount": True
        },
        {
            "value_id": "two_months_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "60日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 59],
                "_registered_at": [0, 0]
            },
            "hide_result": True,
            "adjust_amount": True
        },
        {
            "value_id": "two_months_ltv",
            "value_name": "60日LTV",
            "value_expr": "two_months_agg_recharge / register_user",
            "adjust_amount": True
        }
    ]
}
